package hot100.logos1To10;

/**
 * @author logos
 * date 2025/7/9 11:49
 * @version v1.0
 * @Package hot100
 */
public class logos4 {


    /**
     * 4.移动零
     * https://leetcode.cn/problems/move-zeroes/?envType=study-plan-v2&envId=top-100-liked
     */
    class Solution1 {
        public void moveZeroes(int[] nums) {
            int stackSize = 0;
            for (int x : nums) {
                if (x != 0) {
                    nums[stackSize++] = x;
                }
            }
            for (int i = stackSize; i < nums.length; i++) {
                nums[i] = 0;
            }
        }
    }

    class Solution2 {
        public void moveZeroes(int[] nums) {
            int left = 0;
            for (int right = 0; right < nums.length; right++) {
                if (nums[right] != 0) {
                    int tmp = nums[left];
                    nums[left] = nums[right];
                    nums[right] = tmp;
                    left++;
                }
            }
        }
    }
}
